/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.recitation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.poemmanager.domain.vo.QueryCriteria;
import me.zhengjie.recitation.domain.Recitation;
import me.zhengjie.recitation.domain.vo.RecitationQueryCriteria;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author hwl
* @date 2024-12-06
**/
@Mapper
public interface RecitationMapper extends BaseMapper<Recitation> {

    IPage<Recitation> findAll(@Param("criteria") RecitationQueryCriteria criteria, Page<Object> page);

    List<Recitation> findAll(@Param("criteria") RecitationQueryCriteria criteria);
    @Select("select * from recitation where author_Name=#{userName}")
    List<Recitation> getRecitationByUserName(String username);

    @Select("select * from recitation where recitation_id=#{recitationId}")
    Recitation getById(Integer recitationId);
    @Select("select recitation_id as object_id,3 as object_type,content ,title from recitation where title like CONCAT('%', #{title}, '%')")
    List<QueryCriteria> queryByTitle(String title);
    @Select("select * from recitation limit 30")
    List<Recitation> getAll();

    @Select("SELECT file_path FROM recitation WHERE recitation_id = #{recitationId}")
    String getFilePathByRecitationId(@Param("recitationId") Integer recitationId);

    @Delete("DELETE from recitation where recitation_id=#{recitationId}")
    void deleteByRecitationId(Integer recitationId);
    @Select("select recitation_id ,file_path from recitation")
    List<Recitation> queryAll();

    @Select("SELECT r.recitation_id, r.author_id, r.poem_id, r.created_at, r.updated_at,\n" +
            "       r.author_name, r.title, r.content, r.comment_count, r.favorite_count, r.like_count\n" +
            "FROM recitation r\n" +
            "INNER JOIN recitation_favorites f ON r.recitation_id = f.object_id\n" +
            "WHERE f.user_name = #{userName}")
    List<Recitation> getMyFavoriteRecitation(String userName);
}